/*
 *    This file is part of CeluMap.
 *
 *    CeluMap is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    CeluMap is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *    Copyright 2006, 2007, 2008 Gonzalo Merayo
 *    gonzalo (at) celumap.com.ar
 *    www.celumap.com.ar
 *
 */

package mapWriters;


import java.io.DataOutputStream;
import java.io.IOException;

import figures.Figure;
import figures.basic.PoliLine;

public class LayerMapWriter extends IndexedMapWriter {

	Class[] clases;
	boolean light;
	long low;
	long high;
	
	LayerMapWriter(Class[] clases, long low, long high, boolean light){
		this.clases = clases;
		this.light = light;
		this.low = low;
		this.high = high;
	}
	
	@Override
	public void addFigure(Figure f) {
		for(Class c: clases)
			if(c.equals(f.getClass()))
				super.addFigure(f);
	}

	public long getLow() {
		return low;
	}

	public long getHight() {
		return high;
	}

	@Override
	public void write(DataOutputStream os) throws IOException {
		if(light){
			//simplify layer
			for(Figure f:figs)
				if (f instanceof PoliLine) {
					PoliLine poli = (PoliLine) f;
					int[] xi = poli.getx();
					int[] yi = poli.gety();
					int[] xf = new int[2];
					int[] yf = new int[2];
					xf[0] = xi[0];
					yf[0] = yi[0];
					xf[1] = xi[xi.length-1];
					yf[1] = yi[yi.length-1];
					poli.setxy(xf, yf);
				}
		}
		super.write(os);
	}

}
